home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / ffield.zip / WEAPONS.QC < prev    next >
Text File  |  1996-10-28  |  26KB  |  1,237 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9. // called by worldspawn
  10. void() W_Precache =
  11. {
  12.     precache_sound ("weapons/r_exp3.wav");  // new rocket explosion
  13.     precache_sound ("weapons/rocket1i.wav");        // spike gun
  14.     precache_sound ("weapons/sgun1.wav");
  15.     precache_sound ("weapons/guncock.wav"); // player shotgun
  16.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  17.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/spike2.wav");  // super spikes
  20.     precache_sound ("weapons/tink1.wav");   // spikes tink (used in c code)
  21.     precache_sound ("weapons/grenade.wav"); // grenade launcher
  22.     precache_sound ("weapons/bounce.wav");          // grenade bounce
  23.     precache_sound ("weapons/shotgn2.wav"); // super shotgun
  24.     precache_sound ("sound/FF/FF_On.wav"); // Force Field On
  25.     precache_sound ("sound/FF/FF_Off.wav"); //Force Field Off
  26.         precache_sound ("sound/FF/FF_Hit.wav"); //Force Field Hit
  27.         precache_sound ("sound/FF/FF_Water.wav"); //Force Field in Water
  28. };
  29.  
  30. float() crandom =
  31. {
  32.     return 2*(random() - 0.5);
  33. };
  34.  
  35. /*
  36. ================
  37. W_FireAxe
  38. ================
  39. */
  40. void() W_FireAxe =
  41. {
  42.     local   vector  source;
  43.     local   vector  org;
  44.  
  45.     source = self.origin + '0 0 16';
  46.     traceline (source, source + v_forward*64, FALSE, self);
  47.     if (trace_fraction == 1.0)
  48.         return;
  49.     
  50.     org = trace_endpos - v_forward*4;
  51.  
  52.     if (trace_ent.takedamage)
  53.     {
  54.         trace_ent.axhitme = 1;
  55.         SpawnBlood (org, '0 0 0', 20);
  56.         T_Damage (trace_ent, self, self, 20);
  57.     }
  58.     else
  59.     {       // hit wall
  60.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  61.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  62.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  63.         WriteCoord (MSG_BROADCAST, org_x);
  64.         WriteCoord (MSG_BROADCAST, org_y);
  65.         WriteCoord (MSG_BROADCAST, org_z);
  66.     }
  67. };
  68.  
  69.  
  70. //============================================================================
  71.  
  72.  
  73. vector() wall_velocity =
  74. {
  75.     local vector    vel;
  76.     
  77.     vel = normalize (self.velocity);
  78.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  79.     vel = vel + 2*trace_plane_normal;
  80.     vel = vel * 200;
  81.     
  82.     return vel;
  83. };
  84.  
  85.  
  86. /*
  87. ================
  88. SpawnMeatSpray
  89. ================
  90. */
  91. void(vector org, vector vel) SpawnMeatSpray =
  92. {
  93.     local   entity missile, mpuff;
  94.     local   vector  org;
  95.  
  96.     missile = spawn ();
  97.     missile.owner = self;
  98.     missile.movetype = MOVETYPE_BOUNCE;
  99.     missile.solid = SOLID_NOT;
  100.  
  101.     makevectors (self.angles);
  102.  
  103.     missile.velocity = vel;
  104.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  105.  
  106.     missile.avelocity = '3000 1000 2000';
  107.     
  108. // set missile duration
  109.     missile.nextthink = time + 1;
  110.     missile.think = SUB_Remove;
  111.  
  112.     setmodel (missile, "progs/zom_gib.mdl");
  113.     setsize (missile, '0 0 0', '0 0 0');            
  114.     setorigin (missile, org);
  115. };
  116.  
  117. /*
  118. ================
  119. SpawnBlood
  120. ================
  121. */
  122. void(vector org, vector vel, float damage) SpawnBlood =
  123. {
  124.     particle (org, vel*0.1, 73, damage*2);
  125. };
  126.  
  127. /*
  128. ================
  129. spawn_touchblood
  130. ================
  131. */
  132. void(float damage) spawn_touchblood =
  133. {
  134.     local vector    vel;
  135.  
  136.     vel = wall_velocity () * 0.2;
  137.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  138. };
  139.  
  140.  
  141. /*
  142. ================
  143. SpawnChunk
  144. ================
  145. */
  146. void(vector org, vector vel) SpawnChunk =
  147. {
  148.     particle (org, vel*0.02, 0, 10);
  149. };
  150.  
  151. /*
  152. ==============================================================================
  153.  
  154. MULTI-DAMAGE
  155.  
  156. Collects multiple small damages into a single damage
  157.  
  158. ==============================================================================
  159. */
  160.  
  161. entity  multi_ent;
  162. float   multi_damage;
  163.  
  164. void() ClearMultiDamage =
  165. {
  166.     multi_ent = world;
  167.     multi_damage = 0;
  168. };
  169.  
  170. void() ApplyMultiDamage =
  171. {
  172.     if (!multi_ent)
  173.         return;
  174.     T_Damage (multi_ent, self, self, multi_damage);
  175. };
  176.  
  177. void(entity hit, float damage) AddMultiDamage =
  178. {
  179.     if (!hit)
  180.         return;
  181.     
  182.     if (hit != multi_ent)
  183.     {
  184.         ApplyMultiDamage ();
  185.         multi_damage = damage;
  186.         multi_ent = hit;
  187.     }
  188.     else
  189.         multi_damage = multi_damage + damage;
  190. };
  191.  
  192. /*
  193. ==============================================================================
  194.  
  195. BULLETS
  196.  
  197. ==============================================================================
  198. */
  199.  
  200. /*
  201. ================
  202. TraceAttack
  203. ================
  204. */
  205. void(float damage, vector dir) TraceAttack =
  206. {
  207.     local   vector  vel, org;
  208.     
  209.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  210.     vel = vel + 2*trace_plane_normal;
  211.     vel = vel * 200;
  212.  
  213.     org = trace_endpos - dir*4;
  214.  
  215.     if (trace_ent.takedamage)
  216.     {
  217.         SpawnBlood (org, vel*0.2, damage);
  218.         AddMultiDamage (trace_ent, damage);
  219.     }
  220.     else
  221.     {
  222.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  223.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  224.         WriteCoord (MSG_BROADCAST, org_x);
  225.         WriteCoord (MSG_BROADCAST, org_y);
  226.         WriteCoord (MSG_BROADCAST, org_z);
  227.     }
  228. };
  229.  
  230. /*
  231. ================
  232. FireBullets
  233.  
  234. Used by shotgun, super shotgun, and enemy soldier firing
  235. Go to the trouble of combining multiple pellets into a single damage call.
  236. ================
  237. */
  238. void(float shotcount, vector dir, vector spread) FireBullets =
  239. {
  240.     local   vector direction;
  241.     local   vector  src;
  242.     
  243.     makevectors(self.v_angle);
  244.  
  245.     src = self.origin + v_forward*10;
  246.     src_z = self.absmin_z + self.size_z * 0.7;
  247.  
  248.     ClearMultiDamage ();
  249.     while (shotcount > 0)
  250.     {
  251.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  252.  
  253.         traceline (src, src + direction*2048, FALSE, self);
  254.         if (trace_fraction != 1.0)
  255.             TraceAttack (4, direction);
  256.  
  257.         shotcount = shotcount - 1;
  258.     }
  259.     ApplyMultiDamage ();
  260. };
  261.  
  262. /*
  263. ================
  264. W_FireShotgun
  265. ================
  266. */
  267. void() W_FireShotgun =
  268. {
  269.     local vector dir;
  270.  
  271.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM); 
  272.  
  273.     self.punchangle_x = -2;
  274.     
  275.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  276.     dir = aim (self, 100000);
  277.     FireBullets (6, dir, '0.04 0.04 0');
  278. };
  279.  
  280.  
  281. /*
  282. ================
  283. W_FireSuperShotgun
  284. ================
  285. */
  286. void() W_FireSuperShotgun =
  287. {
  288.     local vector dir;
  289.  
  290.     if (self.currentammo == 1)
  291.     {
  292.         W_FireShotgun ();
  293.         return;
  294.     }
  295.         
  296.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM); 
  297.  
  298.     self.punchangle_x = -4;
  299.     
  300.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  301.     dir = aim (self, 100000);
  302.     FireBullets (14, dir, '0.14 0.08 0');
  303. };
  304.  
  305.  
  306. /*
  307. ==============================================================================
  308.  
  309. ROCKETS
  310.  
  311. ==============================================================================
  312. */
  313.  
  314. void()  s_explode1      =       [0,             s_explode2] {};
  315. void()  s_explode2      =       [1,             s_explode3] {};
  316. void()  s_explode3      =       [2,             s_explode4] {};
  317. void()  s_explode4      =       [3,             s_explode5] {};
  318. void()  s_explode5      =       [4,             s_explode6] {};
  319. void()  s_explode6      =       [5,             SUB_Remove] {};
  320.  
  321. void() BecomeExplosion =
  322. {
  323.     self.movetype = MOVETYPE_NONE;
  324.     self.velocity = '0 0 0';
  325.     self.touch = SUB_Null;
  326.     setmodel (self, "progs/s_explod.spr");
  327.     self.solid = SOLID_NOT;
  328.     s_explode1 ();
  329. };
  330.  
  331. void() T_MissileTouch =
  332. {
  333.     local float     damg;
  334.  
  335.     if (other == self.owner)
  336.         return;         // don't explode on owner
  337.  
  338.     if (pointcontents(self.origin) == CONTENT_SKY)
  339.     {
  340.         remove(self);
  341.         return;
  342.     }
  343.  
  344.     damg = 100 + random()*20;
  345.     
  346.     if (other.health)
  347.     {
  348.         if (other.classname == "monster_shambler")
  349.             damg = damg * 0.5;      // mostly immune
  350.         T_Damage (other, self, self.owner, damg );
  351.     }
  352.  
  353.     // don't do radius damage to the other, because all the damage
  354.     // was done in the impact
  355.     T_RadiusDamage (self, self.owner, 120, other);
  356.  
  357. //      sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  358.     self.origin = self.origin - 8*normalize(self.velocity);
  359.  
  360.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  361.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  362.     WriteCoord (MSG_BROADCAST, self.origin_x);
  363.     WriteCoord (MSG_BROADCAST, self.origin_y);
  364.     WriteCoord (MSG_BROADCAST, self.origin_z);
  365.  
  366.     BecomeExplosion ();
  367. };
  368.  
  369.  
  370.  
  371. /*
  372. ================
  373. W_FireRocket
  374. ================
  375. */
  376. void() W_FireRocket =
  377. {
  378.     local   entity missile, mpuff;
  379.     
  380.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  381.     
  382.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  383.  
  384.     self.punchangle_x = -2;
  385.  
  386.     missile = spawn ();
  387.     missile.owner = self;
  388.     missile.movetype = MOVETYPE_FLYMISSILE;
  389.     missile.solid = SOLID_BBOX;
  390.         
  391. // set missile speed    
  392.  
  393.     makevectors (self.v_angle);
  394.     missile.velocity = aim(self, 1000);
  395.     missile.velocity = missile.velocity * 1000;
  396.     missile.angles = vectoangles(missile.velocity);
  397.     
  398.     missile.touch = T_MissileTouch;
  399.     
  400. // set missile duration
  401.     missile.nextthink = time + 5;
  402.     missile.think = SUB_Remove;
  403.  
  404.     setmodel (missile, "progs/missile.mdl");
  405.     setsize (missile, '0 0 0', '0 0 0');            
  406.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  407. };
  408.  
  409. /*
  410. ===============================================================================
  411.  
  412. LIGHTNING
  413.  
  414. ===============================================================================
  415. */
  416.  
  417. /*
  418. =================
  419. LightningDamage
  420. =================
  421. */
  422. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  423. {
  424.     local entity            e1, e2;
  425.     local vector            f;
  426.     
  427.     f = p2 - p1;
  428.     normalize (f);
  429.     f_x = 0 - f_y;
  430.     f_y = f_x;
  431.     f_z = 0;
  432.     f = f*16;
  433.  
  434.     e1 = e2 = world;
  435.  
  436.     traceline (p1, p2, FALSE, self);
  437.     if (trace_ent.takedamage)
  438.     {
  439.         particle (trace_endpos, '0 0 100', 225, damage*4);
  440.         T_Damage (trace_ent, from, from, damage);
  441.         if (self.classname == "player")
  442.         {
  443.             if (other.classname == "player")
  444.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  445.         }
  446.     }
  447.     e1 = trace_ent;
  448.  
  449.     traceline (p1 + f, p2 + f, FALSE, self);
  450.     if (trace_ent != e1 && trace_ent.takedamage)
  451.     {
  452.         particle (trace_endpos, '0 0 100', 225, damage*4);
  453.         T_Damage (trace_ent, from, from, damage);
  454.     }
  455.     e2 = trace_ent;
  456.  
  457.     traceline (p1 - f, p2 - f, FALSE, self);
  458.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  459.     {
  460.         particle (trace_endpos, '0 0 100', 225, damage*4);
  461.         T_Damage (trace_ent, from, from, damage);
  462.     }
  463. };
  464.  
  465.  
  466. void() W_FireLightning =
  467. {
  468.     local   vector          org;
  469.  
  470.     if (self.ammo_cells < 1)
  471.     {
  472.         self.weapon = W_BestWeapon ();
  473.         W_SetCurrentAmmo ();
  474.         return;
  475.     }
  476.  
  477. // explode if under water
  478.     if (self.waterlevel > 1)
  479.     {
  480.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  481.         self.ammo_cells = 0;
  482.         W_SetCurrentAmmo ();
  483.         return;
  484.     }
  485.  
  486.     if (self.t_width < time)
  487.     {
  488.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  489.         self.t_width = time + 0.6;
  490.     }
  491.     self.punchangle_x = -2;
  492.  
  493.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  494.  
  495.     org = self.origin + '0 0 16';
  496.     
  497.     traceline (org, org + v_forward*600, TRUE, self);
  498.  
  499.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  500.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  501.     WriteEntity (MSG_BROADCAST, self);
  502.     WriteCoord (MSG_BROADCAST, org_x);
  503.     WriteCoord (MSG_BROADCAST, org_y);
  504.     WriteCoord (MSG_BROADCAST, org_z);
  505.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  506.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  507.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  508.  
  509.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  510. };
  511.  
  512.  
  513. //=============================================================================
  514.  
  515.  
  516. void() GrenadeExplode =
  517. {
  518.     T_RadiusDamage (self, self.owner, 120, world);
  519.  
  520.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  521.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  522.     WriteCoord (MSG_BROADCAST, self.origin_x);
  523.     WriteCoord (MSG_BROADCAST, self.origin_y);
  524.     WriteCoord (MSG_BROADCAST, self.origin_z);
  525.  
  526.     BecomeExplosion ();
  527. };
  528.  
  529. void() GrenadeTouch =
  530. {
  531.     if (other == self.owner)
  532.         return;         // don't explode on owner
  533.     if (other.takedamage == DAMAGE_AIM)
  534.     {
  535.         GrenadeExplode();
  536.         return;
  537.     }
  538.         sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);  // bounce sound
  539.     if (self.velocity == '0 0 0')
  540.         self.avelocity = '0 0 0';
  541. };
  542.  
  543. /*
  544. ================
  545. W_FireGrenade
  546. ================
  547. */
  548. void() W_FireGrenade =
  549. {
  550.     local   entity missile, mpuff;
  551.     
  552.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  553.     
  554.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  555.  
  556.     self.punchangle_x = -2;
  557.  
  558.     missile = spawn ();
  559.     missile.owner = self;
  560.     missile.movetype = MOVETYPE_BOUNCE;
  561.     missile.solid = SOLID_BBOX;
  562.     missile.classname = "grenade";
  563.         
  564. // set missile speed    
  565.  
  566.     makevectors (self.v_angle);
  567.  
  568.     if (self.v_angle_x)
  569.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  570.     else
  571.     {
  572.         missile.velocity = aim(self, 10000);
  573.         missile.velocity = missile.velocity * 600;
  574.         missile.velocity_z = 200;
  575.     }
  576.  
  577.     missile.avelocity = '300 300 300';
  578.  
  579.     missile.angles = vectoangles(missile.velocity);
  580.     
  581.     missile.touch = GrenadeTouch;
  582.     
  583. // set missile duration
  584.     missile.nextthink = time + 2.5;
  585.     missile.think = GrenadeExplode;
  586.  
  587.     setmodel (missile, "progs/grenade.mdl");
  588.     setsize (missile, '0 0 0', '0 0 0');            
  589.     setorigin (missile, self.origin);
  590. };
  591.  
  592.  
  593. //=============================================================================
  594.  
  595. void() spike_touch;
  596. void() superspike_touch;
  597.  
  598.  
  599. /*
  600. ===============
  601. launch_spike
  602.  
  603. Used for both the player and the ogre
  604. ===============
  605. */
  606. void(vector org, vector dir) launch_spike =
  607. {
  608.     newmis = spawn ();
  609.     newmis.owner = self;
  610.     newmis.movetype = MOVETYPE_FLYMISSILE;
  611.     newmis.solid = SOLID_BBOX;
  612.  
  613.     newmis.angles = vectoangles(dir);
  614.     
  615.     newmis.touch = spike_touch;
  616.     newmis.classname = "spike";
  617.     newmis.think = SUB_Remove;
  618.     newmis.nextthink = time + 6;
  619.     setmodel (newmis, "progs/spike.mdl");
  620.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);               
  621.     setorigin (newmis, org);
  622.  
  623.     newmis.velocity = dir * 1000;
  624. };
  625.  
  626. void() W_FireSuperSpikes =
  627. {
  628.     local vector    dir;
  629.     local entity    old;
  630.     
  631.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  632.     self.attack_finished = time + 0.2;
  633.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  634.     dir = aim (self, 1000);
  635.     launch_spike (self.origin + '0 0 16', dir);
  636.     newmis.touch = superspike_touch;
  637.     setmodel (newmis, "progs/s_spike.mdl");
  638.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);               
  639.     self.punchangle_x = -2;
  640. };
  641.  
  642. void(float ox) W_FireSpikes =
  643. {
  644.     local vector    dir;
  645.     local entity    old;
  646.     
  647.     makevectors (self.v_angle);
  648.     
  649.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  650.     {
  651.         W_FireSuperSpikes ();
  652.         return;
  653.     }
  654.  
  655.     if (self.ammo_nails < 1)
  656.     {
  657.         self.weapon = W_BestWeapon ();
  658.         W_SetCurrentAmmo ();
  659.         return;
  660.     }
  661.  
  662.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  663.     self.attack_finished = time + 0.2;
  664.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  665.     dir = aim (self, 1000);
  666.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  667.  
  668.     self.punchangle_x = -2;
  669. };
  670.  
  671.  
  672.  
  673. .float hit_z;
  674. void() spike_touch =
  675. {
  676. local float rand;
  677.     if (other == self.owner)
  678.         return;
  679.  
  680.     if (other.solid == SOLID_TRIGGER)
  681.         return; // trigger field, do nothing
  682.  
  683.     if (pointcontents(self.origin) == CONTENT_SKY)
  684.     {
  685.         remove(self);
  686.         return;
  687.     }
  688.     
  689. // hit something that bleeds
  690.     if (other.takedamage)
  691.     {
  692.         spawn_touchblood (9);
  693.         T_Damage (other, self, self.owner, 9);
  694.     }
  695.     else
  696.     {
  697.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  698.         
  699.         if (self.classname == "wizspike")
  700.             {
  701.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  702.             }
  703.         else if (self.classname == "knightspike")
  704.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  705.         else
  706.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  707.         WriteCoord (MSG_BROADCAST, self.origin_x);
  708.         WriteCoord (MSG_BROADCAST, self.origin_y);
  709.         WriteCoord (MSG_BROADCAST, self.origin_z);
  710.     }
  711.  
  712.     remove(self);
  713.  
  714. };
  715.  
  716. void() superspike_touch =
  717. {
  718. local float rand;
  719.     if (other == self.owner)
  720.         return;
  721.  
  722.     if (other.solid == SOLID_TRIGGER)
  723.         return; // trigger field, do nothing
  724.  
  725.     if (pointcontents(self.origin) == CONTENT_SKY)
  726.     {
  727.         remove(self);
  728.         return;
  729.     }
  730.     
  731. // hit something that bleeds
  732.     if (other.takedamage)
  733.     {
  734.         spawn_touchblood (18);
  735.         T_Damage (other, self, self.owner, 18);
  736.     }
  737.     else
  738.     {
  739.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  740.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  741.         WriteCoord (MSG_BROADCAST, self.origin_x);
  742.         WriteCoord (MSG_BROADCAST, self.origin_y);
  743.         WriteCoord (MSG_BROADCAST, self.origin_z);
  744.     }
  745.  
  746.     remove(self);
  747.  
  748. };
  749.  
  750.  
  751. /*
  752. ===============================================================================
  753.  
  754. PLAYER WEAPON USE
  755.  
  756. ===============================================================================
  757. */
  758.  
  759. void() W_SetCurrentAmmo =
  760. {
  761.     player_run ();          // get out of any weapon firing states
  762.  
  763.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  764.     
  765.     if (self.weapon == IT_AXE)
  766.     {
  767.         self.currentammo = 0;
  768.         self.weaponmodel = "progs/v_axe.mdl";
  769.         self.weaponframe = 0;
  770.     }
  771.     else if (self.weapon == IT_SHOTGUN)
  772.     {
  773.         self.currentammo = self.ammo_shells;
  774.         self.weaponmodel = "progs/v_shot.mdl";
  775.         self.weaponframe = 0;
  776.         self.items = self.items | IT_SHELLS;
  777.     }
  778.     else if (self.weapon == IT_SUPER_SHOTGUN)
  779.     {
  780.         self.currentammo = self.ammo_shells;
  781.         self.weaponmodel = "progs/v_shot2.mdl";
  782.         self.weaponframe = 0;
  783.         self.items = self.items | IT_SHELLS;
  784.     }
  785.     else if (self.weapon == IT_NAILGUN)
  786.     {
  787.         self.currentammo = self.ammo_nails;
  788.         self.weaponmodel = "progs/v_nail.mdl";
  789.         self.weaponframe = 0;
  790.         self.items = self.items | IT_NAILS;
  791.     }
  792.     else if (self.weapon == IT_SUPER_NAILGUN)
  793.     {
  794.         self.currentammo = self.ammo_nails;
  795.         self.weaponmodel = "progs/v_nail2.mdl";
  796.         self.weaponframe = 0;
  797.         self.items = self.items | IT_NAILS;
  798.     }
  799.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  800.     {
  801.         self.currentammo = self.ammo_rockets;
  802.         self.weaponmodel = "progs/v_rock.mdl";
  803.         self.weaponframe = 0;
  804.         self.items = self.items | IT_ROCKETS;
  805.     }
  806.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  807.     {
  808.         self.currentammo = self.ammo_rockets;
  809.         self.weaponmodel = "progs/v_rock2.mdl";
  810.         self.weaponframe = 0;
  811.         self.items = self.items | IT_ROCKETS;
  812.     }
  813.     else if (self.weapon == IT_LIGHTNING)
  814.     {
  815.         self.currentammo = self.ammo_cells;
  816.         self.weaponmodel = "progs/v_light.mdl";
  817.         self.weaponframe = 0;
  818.         self.items = self.items | IT_CELLS;
  819.     }
  820.     else
  821.     {
  822.         self.currentammo = 0;
  823.         self.weaponmodel = "";
  824.         self.weaponframe = 0;
  825.     }
  826. };
  827.  
  828. float() W_BestWeapon =
  829. {
  830.     local   float   it;
  831.     
  832.     it = self.items;
  833.  
  834.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  835.         return IT_LIGHTNING;
  836.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  837.         return IT_SUPER_NAILGUN;
  838.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  839.         return IT_SUPER_SHOTGUN;
  840.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  841.         return IT_NAILGUN;
  842.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  843.         return IT_SHOTGUN;
  844.         
  845. /*
  846.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  847.         return IT_ROCKET_LAUNCHER;
  848.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  849.         return IT_GRENADE_LAUNCHER;
  850.  
  851. */
  852.  
  853.     return IT_AXE;
  854. };
  855.  
  856. float() W_CheckNoAmmo =
  857. {
  858.     if (self.currentammo > 0)
  859.         return TRUE;
  860.  
  861.     if (self.weapon == IT_AXE)
  862.         return TRUE;
  863.     
  864.     self.weapon = W_BestWeapon ();
  865.  
  866.     W_SetCurrentAmmo ();
  867.     
  868. // drop the weapon down
  869.     return FALSE;
  870. };
  871.  
  872. /*
  873. ============
  874. W_Attack
  875.  
  876. An attack impulse can be triggered now
  877. ============
  878. */
  879. void()  player_axe1;
  880. void()  player_axeb1;
  881. void()  player_axec1;
  882. void()  player_axed1;
  883. void()  player_shot1;
  884. void()  player_nail1;
  885. void()  player_light1;
  886. void()  player_rocket1;
  887.  
  888. void() W_Attack =
  889. {
  890.     local   float   r;
  891.  
  892.     if (!W_CheckNoAmmo ())
  893.         return;
  894.  
  895.     makevectors     (self.v_angle);                 // calculate forward angle for velocity
  896.     self.show_hostile = time + 1;   // wake monsters up
  897.  
  898.     if (self.weapon == IT_AXE)
  899.     {
  900.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  901.         r = random();
  902.         if (r < 0.25)
  903.             player_axe1 ();
  904.         else if (r<0.5)
  905.             player_axeb1 ();
  906.         else if (r<0.75)
  907.             player_axec1 ();
  908.         else
  909.             player_axed1 ();
  910.         self.attack_finished = time + 0.5;
  911.     }
  912.     else if (self.weapon == IT_SHOTGUN)
  913.     {
  914.         player_shot1 ();
  915.         W_FireShotgun ();
  916.         self.attack_finished = time + 0.5;
  917.     }
  918.     else if (self.weapon == IT_SUPER_SHOTGUN)
  919.     {
  920.         player_shot1 ();
  921.         W_FireSuperShotgun ();
  922.         self.attack_finished = time + 0.7;
  923.     }
  924.     else if (self.weapon == IT_NAILGUN)
  925.     {
  926.         player_nail1 ();
  927.     }
  928.     else if (self.weapon == IT_SUPER_NAILGUN)
  929.     {
  930.         player_nail1 ();
  931.     }
  932.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  933.     {
  934.         player_rocket1();
  935.         W_FireGrenade();
  936.         self.attack_finished = time + 0.6;
  937.     }
  938.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  939.     {
  940.         player_rocket1();
  941.         W_FireRocket();
  942.         self.attack_finished = time + 0.8;
  943.     }
  944.     else if (self.weapon == IT_LIGHTNING)
  945.     {
  946.         player_light1();
  947.         self.attack_finished = time + 0.1;
  948.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  949.     }
  950. };
  951.  
  952. /*
  953. ============
  954. W_ChangeWeapon
  955.  
  956. ============
  957. */
  958. void() W_ChangeWeapon =
  959. {
  960.     local   float   it, am, fl;
  961.     
  962.     it = self.items;
  963.     am = 0;
  964.     
  965.     if (self.impulse == 1)
  966.     {
  967.         fl = IT_AXE;
  968.     }
  969.     else if (self.impulse == 2)
  970.     {
  971.         fl = IT_SHOTGUN;
  972.         if (self.ammo_shells < 1)
  973.             am = 1;
  974.     }
  975.     else if (self.impulse == 3)
  976.     {
  977.         fl = IT_SUPER_SHOTGUN;
  978.         if (self.ammo_shells < 2)
  979.             am = 1;
  980.     }        
  981.     else if (self.impulse == 4)
  982.     {
  983.         fl = IT_NAILGUN;
  984.         if (self.ammo_nails < 1)
  985.             am = 1;
  986.     }
  987.     else if (self.impulse == 5)
  988.     {
  989.         fl = IT_SUPER_NAILGUN;
  990.         if (self.ammo_nails < 2)
  991.             am = 1;
  992.     }
  993.     else if (self.impulse == 6)
  994.     {
  995.         fl = IT_GRENADE_LAUNCHER;
  996.         if (self.ammo_rockets < 1)
  997.             am = 1;
  998.     }
  999.     else if (self.impulse == 7)
  1000.     {
  1001.         fl = IT_ROCKET_LAUNCHER;
  1002.         if (self.ammo_rockets < 1)
  1003.             am = 1;
  1004.     }
  1005.     else if (self.impulse == 8)
  1006.     {
  1007.         fl = IT_LIGHTNING;
  1008.         if (self.ammo_cells < 1)
  1009.             am = 1;
  1010.     }
  1011.  
  1012.     self.impulse = 0;
  1013.     
  1014.     if (!(self.items & fl))
  1015.     {       // don't have the weapon or the ammo
  1016.         sprint (self, "no weapon.\n");
  1017.         return;
  1018.     }
  1019.     
  1020.     if (am)
  1021.     {       // don't have the ammo
  1022.         sprint (self, "not enough ammo.\n");
  1023.         return;
  1024.     }
  1025.  
  1026. //
  1027. // set weapon, set ammo
  1028. //
  1029.     self.weapon = fl;               
  1030.     W_SetCurrentAmmo ();
  1031. };
  1032.  
  1033. /*
  1034. ============
  1035. CheatCommand
  1036. ============
  1037. */
  1038. void() CheatCommand =
  1039. {
  1040.     if (deathmatch || coop)
  1041.         return;
  1042.  
  1043.     self.ammo_rockets = 100;
  1044.     self.ammo_nails = 200;
  1045.     self.ammo_shells = 100;
  1046.     self.items = self.items | 
  1047.         IT_AXE |
  1048.         IT_SHOTGUN |
  1049.         IT_SUPER_SHOTGUN |
  1050.         IT_NAILGUN |
  1051.         IT_SUPER_NAILGUN |
  1052.         IT_GRENADE_LAUNCHER |
  1053.         IT_ROCKET_LAUNCHER |
  1054.         IT_KEY1 | IT_KEY2;
  1055.  
  1056.     self.ammo_cells = 200;
  1057.     self.items = self.items | IT_LIGHTNING;
  1058.  
  1059.     self.weapon = IT_ROCKET_LAUNCHER;
  1060.     self.impulse = 0;
  1061.     W_SetCurrentAmmo ();
  1062. };
  1063.  
  1064. /*
  1065. ============
  1066. CycleWeaponCommand
  1067.  
  1068. Go to the next weapon with ammo
  1069. ============
  1070. */
  1071. void() CycleWeaponCommand =
  1072. {
  1073.     local   float   it, am;
  1074.     
  1075.     it = self.items;
  1076.     self.impulse = 0;
  1077.     
  1078.     while (1)
  1079.     {
  1080.         am = 0;
  1081.  
  1082.         if (self.weapon == IT_LIGHTNING)
  1083.         {
  1084.             self.weapon = IT_AXE;
  1085.         }
  1086.         else if (self.weapon == IT_AXE)
  1087.         {
  1088.             self.weapon = IT_SHOTGUN;
  1089.             if (self.ammo_shells < 1)
  1090.                 am = 1;
  1091.         }
  1092.         else if (self.weapon == IT_SHOTGUN)
  1093.         {
  1094.             self.weapon = IT_SUPER_SHOTGUN;
  1095.             if (self.ammo_shells < 2)
  1096.                 am = 1;
  1097.         }               
  1098.                 else if (self.weapon == IT_SUPER_SHOTGUN)
  1099.         {
  1100.             self.weapon = IT_NAILGUN;
  1101.             if (self.ammo_nails < 1)
  1102.                 am = 1;
  1103.         }
  1104.         else if (self.weapon == IT_NAILGUN)
  1105.         {
  1106.             self.weapon = IT_SUPER_NAILGUN;
  1107.             if (self.ammo_nails < 2)
  1108.                 am = 1;
  1109.         }
  1110.         else if (self.weapon == IT_SUPER_NAILGUN)
  1111.         {
  1112.             self.weapon = IT_GRENADE_LAUNCHER;
  1113.             if (self.ammo_rockets < 1)
  1114.                 am = 1;
  1115.         }
  1116.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1117.         {
  1118.             self.weapon = IT_ROCKET_LAUNCHER;
  1119.             if (self.ammo_rockets < 1)
  1120.                 am = 1;
  1121.         }
  1122.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1123.         {
  1124.             self.weapon = IT_LIGHTNING;
  1125.             if (self.ammo_cells < 1)
  1126.                 am = 1;
  1127.         }
  1128.     
  1129.         if ( (self.items & self.weapon) && am == 0)
  1130.         {
  1131.             W_SetCurrentAmmo ();
  1132.             return;
  1133.         }
  1134.     }
  1135.  
  1136. };
  1137.  
  1138. /*
  1139. ============
  1140. ServerflagsCommand
  1141.  
  1142. Just for development
  1143. ============
  1144. */
  1145. void() ServerflagsCommand =
  1146. {
  1147.     serverflags = serverflags * 2 + 1;
  1148. };
  1149.  
  1150. void() QuadCheat =
  1151. {
  1152.     if (deathmatch || coop)
  1153.         return;
  1154.     self.super_time = 1;
  1155.     self.super_damage_finished = time + 30;
  1156.     self.items = self.items | IT_QUAD;
  1157.     dprint ("quad cheat\n");
  1158. };
  1159.  
  1160. /*
  1161. ============
  1162. ImpulseCommands
  1163.  
  1164. ============
  1165. */
  1166. void() ImpulseCommands =
  1167. {
  1168.     if (self.impulse >= 1 && self.impulse <= 8)
  1169.         W_ChangeWeapon ();
  1170.  
  1171.     if (self.impulse == 9)
  1172.         CheatCommand ();
  1173.     if (self.impulse == 10)
  1174.         CycleWeaponCommand ();
  1175.     if (self.impulse == 11)
  1176.         ServerflagsCommand ();
  1177. // <JRS>
  1178. // This impulse turns the force field on and off.
  1179.     if (self.impulse == 50)
  1180.                 UnionCycleForceField (self);
  1181.         if (self.impulse == 51)
  1182.                 self.Union_FF_HasItem = TRUE;
  1183. // </JRS>
  1184.  
  1185.     if (self.impulse == 255)
  1186.         QuadCheat ();
  1187.         
  1188.     self.impulse = 0;
  1189. // <JRS>
  1190. // Rot down cells if FF is on
  1191.         UnionFFRot(self);
  1192. // </JRS>
  1193. };
  1194.  
  1195. /*
  1196. ============
  1197. W_WeaponFrame
  1198.  
  1199. Called every frame so impulse events can be handled as well as possible
  1200. ============
  1201. */
  1202. void() W_WeaponFrame =
  1203. {
  1204.     if (time < self.attack_finished)
  1205.         return;
  1206.  
  1207.     ImpulseCommands ();
  1208.     
  1209. // check for attack
  1210.     if (self.button0)
  1211.     {
  1212.         SuperDamageSound ();
  1213.         W_Attack ();
  1214.     }
  1215. };
  1216.  
  1217. /*
  1218. ========
  1219. SuperDamageSound
  1220.  
  1221. Plays sound if needed
  1222. ========
  1223. */
  1224. void() SuperDamageSound =
  1225. {
  1226.     if (self.super_damage_finished > time)
  1227.     {
  1228.         if (self.super_sound < time)
  1229.         {
  1230.             self.super_sound = time + 1;
  1231.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1232.         }
  1233.     }
  1234.     return;
  1235. };
  1236.  
  1237.